package com.spring.springbootblog.controller;


import com.spring.springbootblog.common.pojo.request.UserLoginParam;
import com.spring.springbootblog.common.pojo.response.UserInfoResponse;
import com.spring.springbootblog.common.pojo.response.UserLoginResponse;
import com.spring.springbootblog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;


    @RequestMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserLoginParam userParam) {
        log.info("用户登录: username:{}",userParam.getUserName());
        return userService.login(userParam);
    }
    @RequestMapping("getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId) {
        log.info("获取用户信息 userId:{}",userId);
        return userService.getUserInfoById(userId);
    }

    @RequestMapping("getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId) {
        log.info("获取作者信息 blogId:{}",blogId);
        return userService.getAuthorInfo(blogId);
    }

}
